package org.com.java_chatroom.api;

import org.com.java_chatroom.model.Message;
import org.com.java_chatroom.model.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageAPI {
    @Autowired
    private MessageMapper messageMapper;

//    获取指定会话的历史消息
    @RequestMapping("/message")
    public Object getHistoryMessageBySession(int sessionId){
        List<Message> historyMessages = messageMapper.getHistoryMessageBySessionId(sessionId);
//      由于当前获取到的消息是按照时间逆序排列的,但显示到前端还是需要按照时间顺序显示,因此,还需要将list再次逆序
        Collections.reverse(historyMessages);
        return historyMessages;
    }
}
